Skip to content

[game][gui] Fix crash when opening K2 containers#102

Open
Eldbury wants to merge 1 commit intomodawan:masterfrom
Eldbury:fix/k2-container-crash
Open

[game][gui] Fix crash when opening K2 containers#102
Eldbury wants to merge 1 commit intomodawan:masterfrom
Eldbury:fix/k2-container-crash

Conversation

@Eldbury
Copy link
Copy Markdown

@Eldbury Eldbury commented Apr 26, 2026

Summary

Fixes crashes when opening certain KOTOR 2 containers.

The container action path now keeps the original object target instead of assuming every container target is a placeable. This avoids unsafe placeable-only handling for object-shaped container targets such as corpse loot.

Also guards image-button icon rendering when the icon font is unavailable, falling back to the control text font where possible.

Testing

  • Built engine and launcher in RelWithDebInfo on Windows
  • Ran git diff --check upstream/master...HEAD
  • Verified branch diff only includes:
    • src/libs/game/action/opencontainer.cpp
    • src/libs/gui/control/imagebutton.cpp

Manual verification

  • K2: open loot container / corpse container without crashing
  • K2: container UI appears
  • K1: open normal container as regression smoke

@modawan
Copy link
Copy Markdown
Owner

modawan commented Apr 27, 2026

A couple of nitpicks, otherwise LGTM.
isa<Creature>(actor) is a short form of actor.type() == ObjectType::Creature.
Similarly, cast<Creature>(actor) is equivalent to static_cast, but it asserts (crashes in Debug or RelWithDebInfo build) if the object is not of the right type.

auto creatureActor = _game.getObjectById<Creature>(actor.id());
auto placeable = std::static_pointer_cast<Placeable>(_object);
bool reached = creatureActor->navigateTo(placeable->position(), true, kDefaultMaxObjectDistance, dt);
if (!_object || actor.type() != ObjectType::Creature) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!_object || actor.type() != ObjectType::Creature) {
if (!_object || !isa<Creature>(actor)) {

return;
}

auto &creatureActor = static_cast<Creature &>(actor);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto &creatureActor = static_cast<Creature &>(actor);
auto &creatureActor = cast<Creature>(actor);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants